from django.contrib import admin
from .models import KnowledgeBase, KnowledgeDetail

@admin.register(KnowledgeBase)
class KnowledgeBaseAdmin(admin.ModelAdmin):
    list_display = ['knowledge_id', 'title', 'content_type', 'category', 'status', 'uploader', 'upload_date', 'view_count', 'file_name']
    list_filter = ['content_type', 'category', 'status', 'upload_date']
    search_fields = ['title', 'keywords', 'summary', 'uploader']
    readonly_fields = ['knowledge_id', 'upload_date', 'view_count', 'file_size']
    
    fieldsets = (
        ('基本信息', {
            'fields': ('title', 'content_type', 'category', 'status')
        }),
        ('内容信息', {
            'fields': ('summary', 'keywords')
        }),
        ('文件信息', {
            'fields': ('file_name', 'file_path', 'file_size'),
            'classes': ('collapse',)
        }),
        ('上传信息', {
            'fields': ('uploader', 'upload_date', 'view_count'),
            'classes': ('collapse',)
        })
    )

@admin.register(KnowledgeDetail)
class KnowledgeDetailAdmin(admin.ModelAdmin):
    list_display = ['knowledge', 'title', 'uploader', 'upload_time', 'view_count']
    list_filter = ['upload_time']
    search_fields = ['title', 'summary', 'content']
    readonly_fields = ['content_id', 'upload_time', 'view_count']
